package com.whvc;

public class LogicalOperatorsDemo {
    // 主方法定义修正
    public static void main(String[] args) {
        // 定义一些布尔变量用于演示
        boolean a = true;
        boolean b = false;
        int x = 10;
        int y = 20;

        System.out.println("=== 逻辑运算符演示 ===");
        System.out.println("初始值: a = " + a + ", b = " + b + ", x = " + x + ", y = " + y);

        // 逻辑与 (&&) - 两边都为true，结果才为true
        boolean andResult1 = a && !b;
        boolean andResult2 = (x > 5) && (y < 30);
        boolean andResult3 = (x > 15) && (y < 15);

        System.out.println("\n--- 逻辑与 (&&) ---");
        System.out.println("a && !b = " + andResult1);
        System.out.println("(x > 5) && (y < 30) = " + andResult2);
        System.out.println("(x > 15) && (y < 15) = " + andResult3);

        // 逻辑或 (||) - 至少一边为true，结果就为true
        boolean orResult1 = a || b;
        boolean orResult2 = (x < 5) || (y > 15);
        boolean orResult3 = (x < 5) || (y < 15);

        System.out.println("\n--- 逻辑或 (||) ---");
        System.out.println("a || b = " + orResult1);
        System.out.println("(x < 5) || (y > 15) = " + orResult2);
        System.out.println("(x < 5) || (y < 15) = " + orResult3);

        // 逻辑非 (!) - 取反
        boolean notResult1 = !a;
        boolean notResult2 = !b;
        boolean notResult3 = !(x > y);

        System.out.println("\n--- 逻辑非 (!) ---");
        System.out.println("!a = " + notResult1);
        System.out.println("!b = " + notResult2);
        System.out.println("!(x > y) = " + notResult3);

        // 短路特性演示
        System.out.println("\n--- 短路特性演示 ---");
        System.out.println("false && (x++ > 0): " + (false && (x++ > 0)) + ", x = " + x);
        System.out.println("true || (y++ > 0): " + (true || (y++ > 0)) + ", y = " + y);
    }
}